package com.huawei.hms.framework.network.grs;

import android.text.TextUtils;
import com.huawei.hms.framework.common.ContainerUtils;
import com.huawei.hms.framework.common.Logger;
import com.huawei.hms.framework.network.grs.a.c;
import com.sina.weibo.sdk.auth.Oauth2AccessToken;
import java.net.URLEncoder;

public class GrsBaseInfo implements Cloneable {
    private static final String TAG = GrsBaseInfo.class.getSimpleName();
    private String androidVersion;
    private String appName;
    private String countrySource;
    private String deviceModel;
    private String issueCountry;
    private String regCountry;
    private String romVersion;
    private String serCountry;
    private String uid;
    private String versionName;

    private StringBuffer getStringBuffer(StringBuffer stringBuffer, boolean z) {
        Object androidVersion = getAndroidVersion();
        if (!TextUtils.isEmpty(androidVersion)) {
            if (!TextUtils.isEmpty(stringBuffer.toString())) {
                stringBuffer.append(ContainerUtils.FIELD_DELIMITER);
            }
            stringBuffer.append("android_version");
            stringBuffer.append(ContainerUtils.KEY_VALUE_DELIMITER);
            stringBuffer.append(androidVersion);
        }
        androidVersion = getRomVersion();
        if (!TextUtils.isEmpty(androidVersion)) {
            if (!TextUtils.isEmpty(stringBuffer.toString())) {
                stringBuffer.append(ContainerUtils.FIELD_DELIMITER);
            }
            stringBuffer.append("rom_version");
            stringBuffer.append(ContainerUtils.KEY_VALUE_DELIMITER);
            stringBuffer.append(androidVersion);
        }
        androidVersion = getDeviceModel();
        if (!TextUtils.isEmpty(androidVersion)) {
            if (!TextUtils.isEmpty(stringBuffer.toString())) {
                stringBuffer.append(ContainerUtils.FIELD_DELIMITER);
            }
            stringBuffer.append("device_model");
            stringBuffer.append(ContainerUtils.KEY_VALUE_DELIMITER);
            stringBuffer.append(androidVersion);
        }
        androidVersion = c.a().b();
        if (!(TextUtils.isEmpty(androidVersion) || z)) {
            try {
                String encode = URLEncoder.encode(androidVersion, "UTF-8");
                if (!TextUtils.isEmpty(stringBuffer.toString())) {
                    stringBuffer.append(ContainerUtils.FIELD_DELIMITER);
                }
                stringBuffer.append("cp");
                stringBuffer.append(ContainerUtils.KEY_VALUE_DELIMITER);
                stringBuffer.append(encode);
            } catch (Throwable e) {
                Logger.e(TAG, "cp UnsupportedEncodingException.", e);
            }
        }
        androidVersion = getCountrySource();
        if (!TextUtils.isEmpty(androidVersion)) {
            if (!TextUtils.isEmpty(stringBuffer.toString())) {
                stringBuffer.append(ContainerUtils.FIELD_DELIMITER);
            }
            stringBuffer.append("country_source");
            stringBuffer.append(ContainerUtils.KEY_VALUE_DELIMITER);
            stringBuffer.append(androidVersion);
        }
        return stringBuffer;
    }

    public GrsBaseInfo clone() {
        return (GrsBaseInfo) super.clone();
    }

    public GrsBaseInfo copy() {
        GrsBaseInfo grsBaseInfo = new GrsBaseInfo();
        grsBaseInfo.setAppName(this.appName);
        grsBaseInfo.setSerCountry(this.serCountry);
        grsBaseInfo.setRegCountry(this.regCountry);
        grsBaseInfo.setIssueCountry(this.issueCountry);
        grsBaseInfo.setCountrySource(this.countrySource);
        grsBaseInfo.setAndroidVersion(this.androidVersion);
        grsBaseInfo.setDeviceModel(this.deviceModel);
        grsBaseInfo.setRomVersion(this.romVersion);
        grsBaseInfo.setUid(this.uid);
        grsBaseInfo.setVersionName(this.versionName);
        return grsBaseInfo;
    }

    public String getAndroidVersion() {
        return this.androidVersion;
    }

    public String getAppName() {
        return this.appName;
    }

    public String getCountrySource() {
        return this.countrySource;
    }

    public String getDeviceModel() {
        return this.deviceModel;
    }

    public String getGrsParasKey(boolean z, boolean z2) {
        StringBuffer stringBuffer = new StringBuffer();
        Object appName = getAppName();
        if (!TextUtils.isEmpty(appName)) {
            stringBuffer.append("app_name");
            stringBuffer.append(ContainerUtils.KEY_VALUE_DELIMITER);
            stringBuffer.append(appName);
        }
        appName = getGrsReqParamJoint(z, z2);
        if (!TextUtils.isEmpty(appName)) {
            stringBuffer.append(ContainerUtils.FIELD_DELIMITER);
            stringBuffer.append(appName);
        }
        return stringBuffer.toString();
    }

    public String getGrsReqParamJoint(boolean z, boolean z2) {
        StringBuffer stringBuffer = new StringBuffer();
        Object versionName = getVersionName();
        if (!TextUtils.isEmpty(versionName)) {
            stringBuffer.append("app_version").append(ContainerUtils.KEY_VALUE_DELIMITER).append(versionName);
        }
        String uid = getUid();
        if (!TextUtils.isEmpty(uid)) {
            if (!TextUtils.isEmpty(stringBuffer.toString())) {
                stringBuffer.append(ContainerUtils.FIELD_DELIMITER);
            }
            stringBuffer.append(Oauth2AccessToken.KEY_UID).append(ContainerUtils.KEY_VALUE_DELIMITER);
            if (z) {
                stringBuffer.append(com.huawei.hms.framework.network.grs.c.c.b(uid));
            } else if (z2) {
                stringBuffer.append(com.huawei.hms.framework.network.grs.c.c.a(uid));
            } else {
                stringBuffer.append(uid);
            }
        }
        versionName = getRegCountry();
        if (!(TextUtils.isEmpty(versionName) || GrsBaseInfo$CountryCodeSource.UNKNOWN.equals(versionName))) {
            if (!TextUtils.isEmpty(stringBuffer.toString())) {
                stringBuffer.append(ContainerUtils.FIELD_DELIMITER);
            }
            stringBuffer.append("reg_country").append(ContainerUtils.KEY_VALUE_DELIMITER).append(versionName);
        }
        versionName = getSerCountry();
        if (!(TextUtils.isEmpty(versionName) || GrsBaseInfo$CountryCodeSource.UNKNOWN.equals(versionName))) {
            if (!TextUtils.isEmpty(stringBuffer.toString())) {
                stringBuffer.append(ContainerUtils.FIELD_DELIMITER);
            }
            stringBuffer.append("ser_country");
            stringBuffer.append(ContainerUtils.KEY_VALUE_DELIMITER);
            stringBuffer.append(versionName);
        }
        versionName = getIssueCountry();
        if (!(TextUtils.isEmpty(versionName) || GrsBaseInfo$CountryCodeSource.UNKNOWN.equals(versionName))) {
            if (!TextUtils.isEmpty(stringBuffer.toString())) {
                stringBuffer.append(ContainerUtils.FIELD_DELIMITER);
            }
            stringBuffer.append("issue_country");
            stringBuffer.append(ContainerUtils.KEY_VALUE_DELIMITER);
            stringBuffer.append(versionName);
        }
        return getStringBuffer(stringBuffer, z2).toString();
    }

    public String getIssueCountry() {
        return this.issueCountry;
    }

    public String getRegCountry() {
        return this.regCountry;
    }

    public String getRomVersion() {
        return this.romVersion;
    }

    public String getSerCountry() {
        return this.serCountry;
    }

    public String getUid() {
        return this.uid;
    }

    public String getVersionName() {
        return this.versionName;
    }

    public void setAndroidVersion(String str) {
        this.androidVersion = str;
    }

    public void setAppName(String str) {
        this.appName = str;
    }

    public void setCountrySource(String str) {
        this.countrySource = str;
    }

    public void setDeviceModel(String str) {
        this.deviceModel = str;
    }

    public void setIssueCountry(String str) {
        this.issueCountry = str;
    }

    public void setRegCountry(String str) {
        this.regCountry = str;
    }

    public void setRomVersion(String str) {
        this.romVersion = str;
    }

    public void setSerCountry(String str) {
        this.serCountry = str;
    }

    public void setUid(String str) {
        this.uid = str;
    }

    public void setVersionName(String str) {
        this.versionName = str;
    }
}
